﻿Public Class XRAYPART
    Dim connect As CONDB = CONDB.NewConnection()
    Dim selectsequen As Boolean = False
    Dim PROVIDER_Check As New PROVIDERSCLASS

    Private Sub XRAYPART_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Dim objSelectDataMaspartxray As New MASPARTXRAY
        SelectDatagridMaspartxray()

        objSelectDataMaspartxray.loadcombobox(CXRYIDCombo)
        CXRYIDCombo.SelectedValue = -1

        DesignForm(Me)
        DesignGrid(MASPARTXRAYGrid)

        PROVIDER_Check.GETHOSEM(CInt(main.txtUserRequest.Text.Trim), Convert.ToString(Me.Tag))
    End Sub

    Private Sub SelectDatagridMaspartxray()
        Dim objSelectDatamaspartxray As New MASPARTXRAY
        Dim maspartrayData As DataTable
        maspartrayData = connect.GetTable(objSelectDatamaspartxray.selectMaspartxray_)
        MASPARTXRAYGrid.PrimaryGrid.DataSource = maspartrayData
    End Sub

    Private Sub MASPARTXRAYGrid_CellClick(sender As Object, e As DevComponents.DotNetBar.SuperGrid.GridCellClickEventArgs) Handles MASPARTXRAYGrid.CellClick
        Dim grid As DevComponents.DotNetBar.SuperGrid.GridRow
        grid = e.GridPanel.ActiveRow
        'f.TXT_CID.Text = grid.Cells.Item(2).Value
        SXRYIDTxt.Text = CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("ID ส่วน").Value()
        CXRYIDCombo.SelectedValue = CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("ID ประเภท").Value()
        CODEPARTTxt.Text = CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("CODE").Value()
        SXRYNAMETxt.Text = CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("ชื่อส่วน").Value()
        If CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("สถานะการเปิดใช้งาน").Value() = True Then
            MasPartxrayStatusChk.Checked = True
        Else
            MasPartxrayStatusChk.Checked = False
        End If
        addMaspartxray.Enabled = False
    End Sub

    Private Sub addMaspartxray_Click(sender As Object, e As EventArgs) Handles addMaspartxray.Click
        If main.PROVIDERPOLICIES.checklogin_user_ = True Then
            If PROVIDER_Check.PADD_ = True Then
                If CXRYIDCombo.SelectedValue <> Nothing And CODEPARTTxt.Text.ToString.Length > 0 And SXRYNAMETxt.Text.ToString.Length > 0 Then

                    Dim objInsertData As New MASPARTXRAY
                    objInsertData.CXRYID_ = CXRYIDCombo.SelectedValue
                    objInsertData.CODE_ = CODEPARTTxt.Text
                    objInsertData.SXRYNAME_ = SXRYNAMETxt.Text
                    objInsertData.STATUS_ = MasPartxrayStatusChk.Checked
                    objInsertData.insertMaspartxrayData()

                    SelectDatagridMaspartxray()

                    CXRYIDCombo.SelectedValue = -1
                    CODEPARTTxt.Text = ""
                    SXRYNAMETxt.Text = ""
                    MasPartxrayStatusChk.Checked = False
                Else
                    MsgBox("โปรดระบุข้อมูลให้ครบถ้วน", MsgBoxStyle.Critical)
                End If
            Else
                MsgBox(PROVIDER_Check.PADDMSG_)
            End If
        Else
            TOASTCLASS.gloadToastMSG(Me, main.PROVIDERPOLICIES.LOGINUSERMSG_)
            main.txtUserRequest.Focus()
        End If
    End Sub

    Private Sub editMaspartxray_Click(sender As Object, e As EventArgs) Handles editMaspartxray.Click
        If main.PROVIDERPOLICIES.checklogin_user_ = True Then
            If PROVIDER_Check.PUPD_ = True Then
                If SXRYIDTxt.Text.ToString.Length > 0 And CXRYIDCombo.SelectedValue <> Nothing And CODEPARTTxt.Text.ToString.Length > 0 And SXRYNAMETxt.Text.ToString.Length > 0 Then
                    Dim editStat As Integer
                    editStat = MsgBox("ท่านต้องการแก้ไขข้อมูลส่วนดังกล่าวใช่หรือไม่", MsgBoxStyle.OkCancel)

                    If editStat = 1 Then
                        Dim objEditData As New MASPARTXRAY
                        objEditData.SXRYID_ = SXRYIDTxt.Text
                        objEditData.CXRYID_ = CXRYIDCombo.SelectedValue
                        objEditData.CODE_ = CODEPARTTxt.Text
                        objEditData.SXRYNAME_ = SXRYNAMETxt.Text
                        objEditData.STATUS_ = MasPartxrayStatusChk.Checked
                        objEditData.editMaspartxrayData()

                        SelectDatagridMaspartxray()

                        CXRYIDCombo.SelectedValue = -1
                        CODEPARTTxt.Text = ""
                        SXRYNAMETxt.Text = ""
                        MasPartxrayStatusChk.Checked = False
                        SXRYIDTxt.Text = ""
                    End If
                Else
                    MsgBox("โปรดระบุข้อมูลให้ครบถ้วน", MsgBoxStyle.Critical)
                End If
                addMaspartxray.Enabled = True
            Else
                MsgBox(PROVIDER_Check.PUPDMSG_)
            End If
        Else
            TOASTCLASS.gloadToastMSG(Me, main.PROVIDERPOLICIES.LOGINUSERMSG_)
            main.txtUserRequest.Focus()
        End If
    End Sub

    Private Sub importExel_Click(sender As Object, e As EventArgs) Handles importExel.Click
        Dim nextform As New IMPORTEXCEL(maspartxray.Text)
        nextform.ShowDialog()
    End Sub

    Private Sub exportExcel_Click(sender As Object, e As EventArgs) Handles exportExcel.Click
        Dim nextform As New IMPORTEXCEL(maspartxray.Text)
        nextform.ShowDialog()
    End Sub
End Class